﻿@{
    Ajax.Dna().Widget()
        .UserPreferences(widget =>
        {
            var id = widget.GenerateFieldID("Body");

            Ajax.Dna().RichTextBox(id)
    .AllowHTMLEditing(false)
    .Options(opts => { opts.Mode = "source"; })
    .Resizable()
    .Height(300)
    .Value(widget.GetString("Body"))
    .ToolPanes(panes =>
    {
        panes.Clear();
        panes.Add().CustomTools(tb =>
        {
            tb.Add().AddCombo(combo =>
            {
                combo.Items(items =>
                {
                    items.AddValue("blockquote", "((({0})))");
                    items.AddValue("Header 1", "=={0}==");
                    items.AddValue("Header 2", "==={0}===");
                    items.AddValue("Header 3", "===={0}====");
                    items.AddValue("Header 4", "====={0}====");
                    items.AddValue("Header 5", "======{0}======");
                })
                .Options(opts =>
                {
                    opts.OnItemSelected = "$dna.insertFormat($(\"#" + id + "\"),ui.value);";
                })
                .DropDownList();

            })
            .AddIcon("d-rte-icon d-rte-toc", "$dna.insertFormat($(\"#" + id + "\"),\"{toc}\");", "")
            .AddIcon("d-rte-icon d-rte-bold", "$dna.insertFormat($(\"#" + id + "\"),\"'''{0}'''\");", "")
            .AddIcon("d-rte-icon d-rte-italic", "$dna.insertFormat($(\"#" + id + "\"),\"''{0}''\");", "")
            .AddIcon("d-rte-icon d-rte-underline", "$dna.insertFormat($(\"#" + id + "\"),'__{0}__');", "")
            .AddIcon("d-rte-icon d-rte-strikeThrough", "$dna.insertFormat($(\"#" + id + "\"),'--{0}--');", "")
            .AddSeparator()
            .AddIcon("d-rte-icon d-rte-insertOrderedList", "$dna.insertFormat($(\"#" + id + "\"),\"#{0}\");", "")
            .AddIcon("d-rte-icon d-rte-insertUnorderedList", "$dna.insertFormat($(\"#" + id + "\"),\"*{0}\");", "")
            .AddSeparator()
            .AddIcon("d-rte-icon d-rte-justifyLeft", "$dna.insertFormat($(\"#" + id + "\"),'<{0}<');", "")
            .AddIcon("d-rte-icon d-rte-justifyRight", "$dna.insertFormat($(\"#" + id + "\"),'>{0}>');", "")
            .AddSeparator()
            .AddIcon("d-rte-icon d-rte-link", "$dna.insertFormat($(\"#" + id + "\"),'[{0}|{0}]');", "")
            .AddIcon("d-rte-icon d-rte-superscript", "$dna.insertFormat($(\"#" + id + "\"),'^^{0}^^');", "")
            .AddIcon("d-rte-icon d-rte-subscript", "$dna.insertFormat($(\"#" + id + "\"),',,{0},,');", "")
            .AddIcon("d-rte-icon d-rte-img", "$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",null,function(_src){$dna.insertFormat($(\"#" + id + "\"),\"[image|{0}|\"+_src+\"]\");});", "")
                //.AddIcon("d-rte-icon d-rte-img", "$dna.insertFormat($(\"#" + id + "\"),'[image|{0}|{0}]');", "")
            .AddIcon("d-rte-icon d-rte-insertHorizontalRule", "$dna.insertFormat($(\"#" + id + "\"),\"----\");", "")
            .AddIcon("d-rte-icon d-rte-insertCode", "$dna.insertFormat($(\"#" + id + "\"),'<code html>{0}</code>');", "");
        });
    })
    .Render();
        })
        .Content(@<text>
    @if (item.UserPreferences["Body"] != null)
    {
        <div style="padding: 10px; margin-top: 5px;">
            @TextEngine.Wiki(item.UserPreferences["Body"].ToString(), topicCssClass: "d-topic")
            @{Html.RegisterStartupScript("var _topic=$('.d-topic'); if (_topic.length) { _topic.dtree(); _topic.before(\"<b>Content table</b>\");}");}
        </div>
    }
    </text>)
.Design(@<text>
    @if (item.UserPreferences["Body"] != null)
    {
        <div style="padding: 10px; margin-top: 5px;">
            @TextEngine.Wiki(item.UserPreferences["Body"].ToString(), enableTracing: true)
        </div>
    }
    </text>)
        .Render();
}
